<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<jsp:useBean id="utilities" class="masterpiece.util.Utilities" scope="session" />    
<%@ page import="java.sql.*"%>
<%@ page import="java.io.*"%>
<%@ page import="java.text.*"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<title>The Mast</title>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<link rel="stylesheet" type="text/css" href="css/stories.css" />
<link href="css/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="css/messages.css" />
</head>
<body>


<div id="container">

<%
int articleId = -1;
try {
	articleId = Integer.parseInt(request.getParameter("id"));
	//out.print("<p class=\"message success\">Got article ID: "+articleId+".</p>");
} catch (NumberFormatException e) {
	out.print("<p class=\"message error\">Invalid article ID: "+e.getMessage()+".</p>");
}

ResultSet article = null;
try {
	 article = utilities.getArticle(articleId);
} catch (Exception e) {
	out.print("<p class=\"message error\">Error fetching article: "+e.getMessage()+".</p>");
}
if (articleId == -1 || article == null || !article.next()) {
	out.print("<p class=\"message error\">No such article.</p>");
} else {
	ResultSet authors  = null;
	ResultSet pictures = null;
	try {
		authors = utilities.getAuthors(articleId);
		//out.print("<p class=\"message success\">Got authors.</p>");
	} catch (Exception e) {
		out.print("<p class=\"message error\">Error getting authors: "+e.getMessage()+".</p>");
	}
	try {
		pictures = utilities.getPicturesForArticle(articleId);
		//out.print("<p class=\"message success\">Got pictures.</p>");
	} catch (Exception e) {
	    out.print("<p class=\"message error\">Error getting pictures: "+e.getMessage()+".</p>");
	}
	
	if (authors != null && pictures != null) {
		int sectionId = article.getInt("section");
	  String[] sections = {
			  "",
			  "News",
			  "Op-Ed",
			  "LuteLife",
			  "International",
			  "Arts &amp; Entertainment",
			  "Sports"
		};
	  String sectionString = sections[sectionId];
	  
	  SimpleDateFormat format = new SimpleDateFormat("MMM d, yyyy");
	  String dateString = format.format(article.getDate("issue"));
	  
	  //out.print("<p class=\"message success\">Got section.</p>");
%>

  <div id="top">
    <span class="section"><%=sectionString%></span>
    <span class="date"><%=dateString%> | Volume LXXXIX, No. 21</span>
    </div>

<div id="menu">
<ul id="MenuBar1" class="MenuBarHorizontal">
      <li> 
        <div align="center"><a href="#">Archive</a> </div>
      </li>
      <li> 
        <div align="center"><a href="#">Sports</a></div>
      </li>
      <li> 
        <div align="center"><a href="#">A&amp;E</a> </div>

      </li>
      <li> 
        <div align="center"><a href="#">International</a></div>
      </li>
      <li> 
        <div align="center"><a href="#">LuteLife</a></div>
      </li>
      <li> 
        <div align="center"><a href="#">Op-Ed</a></div>
      </li>
      <li> 
        <div align="center"><a href="#">News</a></div>
      </li>
      <li> 
        <div align="center"><a href="#">Home</a></div>
      </li>
</ul>
</div>

<div id="newscontainer">
  <div id="rightnews">
      <div id="news"> 
        <h1><%=article.getClob("headline").getSubString(1l,(int)article.getClob("headline").length())%></h1>
        <div id="div"> 
          <h2><%=article.getClob("sub_headline").getSubString(1l,(int)article.getClob("sub_headline").length()) %></h2>
          <h3>
            <% while(authors.next()) { %>
            <%=authors.getString("first_name")+" "+authors.getString("last_name")%><br />
            <% } %>
            <a href="mailto: mast@plu.edu">mast@plu.edu</a>
            <br />
            <br />
            <br />
          </h3>
          <p>
            <%
            InputStream bodyStream = article.getClob("body").getAsciiStream();
            int c = bodyStream.read();
            while(c != -1) {
            	out.write(c);
            	c = bodyStream.read();
            }
            %>
          </p>
          <p></p>
          <p>&nbsp; </p>

          <p><br />
          </p>
          <p><br />
          </p>
          <p><br />
          </p>
          </div>
      </div>
  </div>

  <div id="leftnews">
  <% while (pictures.next()) { %>
      <div id="dompic"> 
        <div align="right"> 
          <img alt="<%=pictures.getClob("alt").getSubString(1l,(int)pictures.getClob("alt").length())%>" src="picture.jsp?large=false&id=<%=pictures.getInt("id")%>" border="1" /> 
          <p class="photocredit"><%=pictures.getClob("credit").getSubString(1l,(int)pictures.getClob("credit").length())%></p> 
          <p><%=pictures.getClob("alt").getSubString(1l,(int)pictures.getClob("alt").length())%></p>
        </div>
      </div>
   <% } %>
    </div>
  <br class="clearfloat" />
</div>

<%  }
	} %>

<div id="info">
<div id="bottommenu">
<ul>
<li><a href="#">Subscribe</a></li>
<li><a href="#">Advertise</a></li>
<li><a href="#">Contact Us</a></li>

</ul>
</div>
<div style="width: 82px;" class="floatleft"><img src="images/rose.png" width="82" height="82" /></div>
<div style="margin-top: 20px; width: 350px;">
  <h1>The Mast<br /></h1>
  Pacific Lutheran University<br />
  University Center, PLU, Tacoma, WA 98447<br />
    Ph: 253.535.7494   Email: <a href="mailto:mast@plu.edu">mast@plu.edu</a></div>

</div>
</div>
</body>
</html>